/// `POST /_matrix/identity/*/validate/msisdn/submitToken`
///
/// Validate the ownership of a phone number.

use crate::{OwnedClientSecret, OwnedSessionId};

/// `/v2/` ([spec])
///
/// [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv2validatemsisdnsubmittoken

// const METADATA: Metadata = metadata! {
//     method: POST,
//     rate_limited: false,
//     authentication: AccessToken,
//     history: {
//         1.0 => "/_matrix/identity/v2/validate/msisdn/submitToken",
//     }
// };

/// Request type for the `validate_msisdn` endpoint.

#[derive(ToSchema, Deserialize, Debug)]
pub struct ValidateMsisdnReqBody {
    /// The session ID, generated by the `requestToken` call.
    pub sid: OwnedSessionId,

    /// The client secret that was supplied to the `requestToken` call.
    pub client_secret: OwnedClientSecret,

    /// The token generated by the `requestToken` call and sent to the user.
    pub token: String,
}

/// Response type for the `validate_msisdn` endpoint.
#[derive(ToSchema,Serialize, Debug)]
pub struct ValidateMsisdnResBody {
    /// Whether the validation was successful or not.
    pub success: bool,
}
impl ValidateMsisdnResBody {
    /// Create a new `Response` with the success status.
    pub fn new(success: bool) -> Self {
        Self { success }
    }
}

/// `GET /_matrix/identity/*/validate/msisdn/submitToken`
///
/// Validate the ownership of a phone number by the end user.
/// `/v2/` ([spec])
///
/// [spec]: https://spec.matrix.org/latest/identity-service-api/#get_matrixidentityv2validatemsisdnsubmittoken

// const METADATA: Metadata = metadata! {
//     method: GET,
//     rate_limited: false,
//     authentication: AccessToken,
//     history: {
//         1.0 => "/_matrix/identity/v2/validate/msisdn/submitToken",
//     }
// };

/// Request type for the `validate_email_by_end_user` endpoint.
#[derive(ToParameters, Deserialize, Debug)]
pub struct ValidateEmailByEndUserReqArgs {
    /// The session ID, generated by the `requestToken` call.
    #[salvo(parameter(parameter_in = Query))]
    pub sid: OwnedSessionId,

    /// The client secret that was supplied to the `requestToken` call.
    #[salvo(parameter(parameter_in = Query))]
    pub client_secret: OwnedClientSecret,

    /// The token generated by the `requestToken` call and sent to the user.
    #[salvo(parameter(parameter_in = Query))]
    pub token: String,
}
/// `POST /_matrix/identity/*/validate/msisdn/requestToken`
///
/// Create a session for validation of a phone number.
/// `/v2/` ([spec])
///
/// [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv2validatemsisdnrequesttoken
// const METADATA: Metadata = metadata! {
//     method: POST,
//     rate_limited: false,
//     authentication: AccessToken,
//     history: {
//         1.0 => "/_matrix/identity/v2/validate/msisdn/requestToken",
//     }
// };

/// Request type for the `create_msisdn_validation_session` endpoint.

#[derive(ToSchema, Deserialize, Debug)]
pub struct CreateMsisdnValidationSessionReqBody {
    /// A unique string generated by the client, and used to identify the validation attempt.
    pub client_secret: OwnedClientSecret,

    /// The two-letter uppercase ISO-3166-1 alpha-2 country code that the number in
    /// `phone_number` should be parsed as if it were dialled from.
    pub country: String,

    /// The phone number to validate.
    pub phone_number: String,

    /// The server will only send an SMS if the send_attempt is a number greater than the most
    /// recent one which it has seen, scoped to that `country` + `phone_number` +
    /// `client_secret` triple.
    pub send_attempt: u64,

    /// When the validation is completed, the identity server will redirect the user to this
    /// URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_link: Option<String>,
}

/// Response type for the `create_msisdn_validation_session` endpoint.
#[derive(ToSchema,Serialize, Debug)]
pub struct CreateMsisdnValidationSessionResBody {
    /// The session ID.
    ///
    /// Session IDs are opaque strings generated by the identity server.
    pub sid: OwnedSessionId,
}
impl CreateMsisdnValidationSessionResBody {
    /// Create a new `Response` with the given session ID.
    pub fn new(sid: OwnedSessionId) -> Self {
        Self { sid }
    }
}
